package logging;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import Filter.Filter;



public class loggerConfig {
	private String path;
	private String formatConsole;
	private String formatFiles;
	private String separator;
	private String level;
//	protected String typeFormatConsole;
	protected String typeFormat;
	private boolean enableConsole;
    private String consoleTypeFilter,consoleValueFilter;
	private Map<String, Filter> files = new HashMap<String, Filter>();
    private boolean hasConsoleFilter;
	private Filter filterConsole;
	private Map<String, ArrayList<String>> destination = new HashMap<String, ArrayList<String>>();
	 
	
	public loggerConfig(String path){
		this.path = path;
		this.enableConsole=false;
		this.separator="-";
		this.hasConsoleFilter=false;
		this.filterConsole=null;
	}
	
	
	private void loadPropierties(PropertiesConfig propertiesConfig){
		propertiesConfig.readConfig();
		this.formatConsole=propertiesConfig.getFormatConsole();
		this.formatFiles=propertiesConfig.getFormatFiles();
		this.separator=propertiesConfig.getSeparator();
		this.level=propertiesConfig.getLevelConfig();
		this.enableConsole=propertiesConfig.enableConsole();
		this.consoleTypeFilter=propertiesConfig.getConsoleTypeFilter();
		this.consoleValueFilter=propertiesConfig.getConsoleValueFilter();
		this.files=propertiesConfig.getMapFiles();
		this.hasConsoleFilter=propertiesConfig.hasConsoleFilter();
		this.filterConsole=propertiesConfig.getFilterConsole();
//		this.typeFormatConsole=propertiesConfig.getTypeFormatConsole();
		this.typeFormat=propertiesConfig.getTypeFormat();
		this.destination = propertiesConfig.getMapDestinationCustom();
		
	}
	
	private void loadXml(XmlConfig xmlConfig){
		xmlConfig.readConfig();
		this.formatConsole=xmlConfig.getFormatConsole();
		this.formatFiles=xmlConfig.getFormatFiles();
		this.separator=xmlConfig.getSeparator();
		this.level=xmlConfig.getLevelConfig();
		this.enableConsole=xmlConfig.enableConsole();
		this.consoleTypeFilter=xmlConfig.getConsoleTypeFilter();
		this.consoleValueFilter=xmlConfig.getConsoleValueFilter();
		this.files=xmlConfig.getMapFiles();
		this.hasConsoleFilter=xmlConfig.hasConsoleFilter();
		this.filterConsole=xmlConfig.getFilterConsole();
//		this.typeFormatConsole=xmlConfig.getTypeFormatConsole();
		this.typeFormat=xmlConfig.getTypeFormat();
		this.destination = xmlConfig.getMapDestinationCustom();
	}
	
	public void readConfig(){		 
		XmlConfig xmlConfig;
		PropertiesConfig propertiesConfig;

		propertiesConfig = new PropertiesConfig(this.path+".properties");
		if(propertiesConfig.isPathValid()){
			loadPropierties(propertiesConfig);
		}
		else{
			xmlConfig = new XmlConfig(this.path+".xml");
			if(xmlConfig.isPathValid()){
				loadXml(xmlConfig);
			}
			else{
				this.loadDefaultValues();
			}
				
			
		}			
				
		 
	 }
	
	
	 public String getLevelConfig(){
		 return this.level;		 
	 }
	
	 
	 public Map<String, Filter> getMapFiles(){
		 return this.files;
	 }

	 
	 public boolean enableConsole(){
		 return this.enableConsole;
	 }
	 
	 
	 public String getFormatConsole(){
		 return this.formatConsole;
	 }
	 
	 public String getFormatFiles(){
		 return this.formatFiles;
	 }
	 	 
	 
	 public String getSeparator(){
		 return this.separator;
	 }

	 
	 public String getConsoleTypeFilter(){
		 return this.consoleTypeFilter;
	 }
	 
	 
	 public String getConsoleValueFilter(){
		 return this.consoleValueFilter;
	 }
	 
	 
	 public boolean hasConsoleFilter(){
		 return (this.hasConsoleFilter);
	 }
	 
	 
     public Filter getFilterConsole(){
    	 return (this.filterConsole);
     }
     
     
//	 public String getTypeFormatConsole(){
//		 return (this.typeFormatConsole);
//	 }
		
	 public String getTypeFormat(){
		 return (this.typeFormat);
	 }
	
	 public Map<String, ArrayList<String>> getMapDestination(){
		 return this.destination;
	 }
     
	 private void loadDefaultValues(){
		 this.formatConsole = LoggerConstants.formatDefault;
		 this.formatFiles = LoggerConstants.formatDefault;
		 this.separator = LoggerConstants.separatorDefault;
		 this.level = LoggerConstants.levelDefault;
//		 this.typeFormatConsole = LoggerConstants.typeFormatDefault;
		 this.typeFormat = LoggerConstants.typeFormatDefault;	 
		 this.enableConsole = true;
		 this.hasConsoleFilter=false;

	 }
}